package com.homer.android.sdk.type.user.builder;

import com.homer.android.sdk.object.db.IOTUserDBManager;
import com.homer.android.sdk.object.db.IUserDB;
import com.homer.android.sdk.type.user.IBEspUser;
import com.homer.android.sdk.user.IEspUser;
import com.homer.iot.esptouch.model.EspUser;



public class BEspUser implements IBEspUser
{
    /*
     * Singleton lazy initialization start
     */
    private IEspUser instanceSingleton = null;
    
    private BEspUser()
    {
        instanceSingleton = new EspUser();
    }
    
    private static class InstanceHolder
    {
        static BEspUser instanceBuilder = new BEspUser();
    }
    
    public static BEspUser getBuilder()
    {
        return InstanceHolder.instanceBuilder;
    }
    
    @Override
    public IEspUser getInstance()
    {
        return instanceSingleton;
    }
    
    /*
     * Singleton lazy initialization end
     */
    
    @Override
    public IEspUser loadUser()
    {
        IUserDB userDB = IOTUserDBManager.getInstance().load();
        if (userDB != null)
        {
            instanceSingleton.setUserId(userDB.getId());
            instanceSingleton.setUserKey(userDB.getKey());
            instanceSingleton.setPhone(userDB.getPhone());
            instanceSingleton.setUserName(userDB.getName());
        }
        return instanceSingleton;
    }
}
